package com.origin.onlinesys.web.controllers.modules.app;

import com.origin.onlinesys.common.controllers.BaseController;
import com.origin.onlinesys.domain.modules.app.AppInfoBean;
import com.origin.onlinesys.service.modules.app.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/6/25.
 */
@Controller
@RequestMapping(value = "/app")
public class AppInfoController extends BaseController{
    @Autowired
    private AppInfoService service;
    @RequestMapping(value = "/add")
    @ResponseBody
    public int add(@ModelAttribute AppInfoBean bean){
        bean.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return service.save(bean);
    }

    @RequestMapping(value = "/getCount")
    @ResponseBody
    public Map getCount(){
        Map map = new HashMap();
        map.put("count",service.getCount());
        return map;
    }

    @RequestMapping(value = "/selectPage")
    public @ResponseBody
    Map selectPage(int pageNum,String startDate, String endDate){
        startDate = getTime(startDate," 00:00:00");endDate = getTime(endDate," 23:59:00");
        return service.selectPage(pageNum,pageSize,startDate,endDate);
    }
    private String getTime(String date,String time){
        if(date == null) return new SimpleDateFormat("yyyy-MM-dd").format(new Date())+time;
        if(date != null && date.trim().length() == 0)return null;
        return date+time;
    }
}
